package com.unknown

import grails.plugins.springsecurity.Secured

@Secured(['ROLE_USER', 'ROLE_ADMIN'])
class PathController {
	def possiblePaths = 
		['Bottom':[fill:'_h-lf.png', bottom:'_h-lb.png', top:'_h-lt.png'],
		 'Top':[fill:'_h-uf.png', bottom:'_h-ub.png', top:'_h-ut.png'],
		 'Vertical':[fill:'_v-f.png',bottom:'_v-l.png',top:'_v-r.png'],
		 'Diagonal 1':[fill:'_d1-rf.png', bottom:'_d1-rt.png',top:'_d1-rb.png'],
		 'Diagonal 2':[fill:'_d1-lf.png', bottom:'_d1-lt.png',top:'_d1-lb.png'],
		 'Diagonal 3':[fill:'_d2-lf.png', bottom:'_d2-rt.png',top:'_d2-rb.png'],
		 'Diagonal 4':[fill:'_d2-rf.png', bottom:'_d2-lt.png',top:'_d2-lb.png'],
		 'Diagonal 5':[fill:'_d3-rf.png', bottom:'_d3-rt.png',top:'_d3-rb.png'],
		 'Diagonal 6':[fill:'_d3-lf.png', bottom:'_d3-lt.png',top:'_d3-lb.png']
		]
	
	def show = {
		def style = params.style ?: 'small'
		def name = params.name ?: 'Path'
		def prefix = params.id ?: 'path-cell'
		def fill = params.fill ? Boolean.parseBoolean(params.fill) : true
        def postFill = params.postFill ? Boolean.parseBoolean(params.postFill) : false;
		def sections = [];
        if( params.fill && !postFill )
            sections += ['_d3-rf.png'];
        sections += ['_d3-rt.png','_d3-rb.png'];
        if( params.fill && postFill )
            sections += ['_d3-rf.png'];

		def path = [name:name, prefix:prefix, sections: sections ]
		[path:path, style:style, segments:possiblePaths]
	}
	
	def list = {
		def columns = params.columns ? params.getInt('columns') : 5;
		def style = params.style ?: 'small';
		if( params.pathName ){
			def paths = []
			possiblePaths.each {
				paths << [name:it.key, prefix:params.pathName, sections:it.value]
			}
			[paths:paths, style:style, columns:columns]
		}else{
			def paths = []
			paths << [name:'Path', fill:'true', prefix:'path-cell', sections:['_d3-rf.png','_d3-rb.png','_d3-rt.png']]
			paths << [name:'Marble', fill:'false', prefix:'circle_marble', sections:['_d3-rt.png','_d3-rb.png']]
			paths << [name:'Sandstone', fill:'false', prefix:'circle_sandstone', sections:['_d3-rt.png','_d3-rb.png']]
			paths << [name:'Fence', fill:'false', prefix:'circle_wood', sections:['_d3-rt.png','_d3-rb.png']]
            paths << [name:'Grass', fill:'true', postFill:'true', prefix:'circle_coastline', sections:['_d3-rt.png','_d3-rb.png', '_d3-rf.png']]
            paths << [name:'Grass', fill:'true', postFill:'true', prefix:'circle_coastline1', sections:['_d3-rt.png','_d3-rb.png', '_d3-rf.png']]
			[paths:paths, style:style, columns:columns]
		}
	}
}
